/*
 * @lc app=leetcode.cn id=257 lang=javascript
 *
 * [257] 二叉树的所有路径
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function(root) {
    // 顺序 中左右
    const res=[]
    if(!root){
        return res
    }
    const queque=[root]
    const paths=['']
    while(queque.length){
        const node=queque.shift()
        let path=paths.shift()
        
        if(!node.left&&!node.right){
            res.push(path+node.val)
            continue
        }
        path+=node.val+'->'
        if(node.left){
            queque.push(node.left)
            paths.push(path)
        }
        if(node.right){
            queque.push(node.right)
            paths.push(path) 
        }
    }
    return res

};
// @lc code=end

